import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:magic_car/res/colors.dart';
import 'package:magic_car/user/userPrivate.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:magic_car/main.dart';
import 'package:package_info/package_info.dart';

class SetPage extends StatefulWidget {
  SetPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<SetPage> {
  String version = 'v1.0.0';
  String localVersion = "v1.0.0";
  initState() {
    super.initState();
    getlocalversion();
    getversion();

    //  startLocations();//获取位置
  }

    getversion() async {
    Map<String, String> map = new Map();
    // map["id"] = pref.getString('uid');

    HttpHelper.post(HttpHelper.API_Version, (data) async {
      //loadpage.close();
      if (data != null) {
        print(data);

        String romot_version = data['VersionName'];
        setState(() {
          version = romot_version;
        });
      }
    }, params: map);
  }

  getlocalversion() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    String localVersions = packageInfo.version;
    setState(() {
      localVersion =  localVersions;
    });
  }

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(
          '关于我们',
          style: TextStyle(color: Colors.black),
        ),
        backgroundColor: Colors.white,
        elevation: 0,
        iconTheme: IconThemeData(
          color: Colors.black, //修改颜色
        ),
      ),
      body: new ListView(
        children: <Widget>[
          new Padding(
            padding: new EdgeInsets.fromLTRB(20.0, 50.0, 20.0, 15.0),
            child: new Column(
              children: <Widget>[
                new Center(
                  child: new Image.asset('resource/images/user/logo2.png',
                      height: 200, width: 200),
                ),
                new Padding(
                  padding: new EdgeInsets.fromLTRB(0, 30, 0, 10),
                  child: new Center(
                    child: Text(
                      '车魔估',
                      style: TextStyle(fontSize: 20),
                    ),
                  ),
                ),
               new Padding(
                    padding: new EdgeInsets.fromLTRB(0, 0, 0, 5),
                    child: new Center(
                      child: Text(
                        "您的版本：" + localVersion,
                        style:
                            TextStyle(fontSize: 13, color: Colours.text_gray),
                      ),
                    ),
                  ),
                  new Padding(
                    padding: new EdgeInsets.fromLTRB(0, 0, 0, 10),
                    child: new Center(
                      child: Text(
                        "最新版本：" + version,
                        style:
                            TextStyle(fontSize: 13, color: Colours.text_gray),
                      ),
                    ),
                  ),
                new Center(
                  child: Text(
                      '车魔估是一款专注二手车行业服务的应用，通过自主研发的线上“二手车检测系统”（包含300多项检测内容）+“二手车保修系统”结合创新的“共享检测师”模式，立志于改善二手车行业“车况不透明”及“售后没保障”的问题。'),
                ),
                Padding(
                  padding: new EdgeInsets.fromLTRB(0, 100, 0, 30),
                  child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Padding(
                          padding: new EdgeInsets.fromLTRB(20, 10, 20, 10),
                          child: Align(
                              alignment: Alignment.centerRight,
                              child: new Container(
                                child: new Material(
                                  //INK可以实现装饰容器
                                  child: new Ink(
                                    //用ink圆角矩形
                                    // color: Colors.red,
                                    decoration: new BoxDecoration(
                                      //背景
                                      color: Colors.white,
                                      //设置四周圆角 角度
                                      borderRadius: BorderRadius.all(
                                          Radius.circular(5.0)),
                                      //设置四周边框
                                      border: new Border.all(
                                          width: 1,
                                          color:
                                              Color.fromRGBO(153, 153, 153, 1)),
                                    ),
                                    child: new InkWell(
                                        //圆角设置,给水波纹也设置同样的圆角
                                        //如果这里不设置就会出现矩形的水波纹效果
                                        borderRadius:
                                            new BorderRadius.circular(15.0),
                                        //设置点击事件回调
                                        onTap: () async {
                                          SharedPreferences pref =
                                              await SharedPreferences
                                                  .getInstance();
                                          pref.clear();
                                          Navigator.of(context)
                                              .pushAndRemoveUntil(
                                                  new MaterialPageRoute(
                                                      builder: (context) =>
                                                          new MyApp()),
                                                  (route) => route == null);
                                        },
                                        child: Container(
                                          //设置 child 居中
                                          alignment: Alignment(0, 0),
                                          height: 40,
                                          width: 185,
                                          child: Text(
                                            "退出登录",
                                            style: TextStyle(
                                                color: Color.fromRGBO(
                                                    153, 153, 153, 1)),
                                          ),
                                        )),
                                  ),
                                ),
                              )
                              // child: new RaisedButton(
                              //   child: Text('申请补考'),
                              //   onPressed: () {},
                              // ),
                              ),
                        ),
                        // Container(height: 40,width:150 ,child:
                        // RaisedButton(
                        //   child: Text('退出登录',),
                        //   color: Color.fromRGBO(181, 181, 181, 1),
                        //   textColor: Colors.white,
                        //   onPressed: (){

                        //   },
                        // ),)
                      ]),
                ),
                Padding(
                    padding: new EdgeInsets.fromLTRB(0, 10, 0, 20),
                    child: new Center(
                      child: GestureDetector(
                          onTap: () {
                            Navigator.of(context)
                                .push(new MaterialPageRoute(builder: (_) {
                              return new preWebPage(
                                  'http://ylz.9ok6.com/app/index.php?i=16&c=entry&m=chemogu&do=mobile&r=car.partnerprivate');
                            }));
                          },
                          child: Text('用户隐私政策')),
                    )),
                new Center(
                  child: Text('技术开发'),
                ),
                new Center(
                  child: Text('云南车魔估科技有限公司'),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
